﻿namespace Baddies.GUI
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;

    /// <summary>
    /// This class is a pre-made console from the
    /// TextInputGUI and textOutputGUI GUINode classes.
    /// </summary>
    public class ConsoleGUI : BoxGUI
    {
        /// <summary>
        /// Initializes a new instance of the ConsoleGUI class,
        /// and adds all the required children node for convenience.
        /// </summary>
        public ConsoleGUI() : base()
        {
            TextOutputGUI textOutput = new TextOutputGUI();
            textOutput.Position = new Vector3(1, 1, 1);
            textOutput.W = 300;
            textOutput.Name = "TextOutput";
            textOutput.ChangeBGColor(Color.Black);
            textOutput.TextColor = Color.White;

            TextInputGUI textInput = new TextInputGUI();
            textInput.Position = new Vector3(1, textOutput.H + 2, 1);
            textInput.W = 300;
            textInput.H = 20;
            textInput.Name = "TextInput";
            textInput.ChangeBGColor(Color.Black);
            textInput.TextColor = Color.White;

            this.Add(0, textInput);
            this.Add(1, textOutput);
            this.FocusedNode = textInput;

            this.Position = new Vector3(100, 100, 1);
            this.W = 302;
            this.H = 3 + textOutput.H + textInput.H;
            this.Name = "Console";
            this.ChangeBGColor(Color.White);
        }

        /// <summary>
        /// Lets the console react to key-presses.
        /// </summary>
        /// <param name="key">Key to react to.</param>
        /// <returns>True if we have reacted and consumed the event, false otherwise.</returns>
        public override bool React(Keys key)
        {
            if (key == Keys.Escape)
            {
                this.Visible = !this.Visible;
                return true;
            }
            else
            {
                return this.FocusedReact(key);
            }
        }
    }
}
